import { FormOption } from "@/components/SuperForm/formType";
import { type FormRules } from "element-plus";

type PointForm = {
  station_name: string;
  category: number | null;
};
// 描述内容
export class FormPoint {
  // 定义变量
  #formData: PointForm = {
    station_name: "",
    category: null,
  };
  // 表单配置项
  #formOption: FormOption = {
    formItems: [
      {
        field: "station_name",
        prop: "station_name",
        type: "input",
        label: "作业点",
        placeholder: "请输入作业点名称",
        colSpan: 24,
        maxlength: 24,
      },
      {
        field: "category",
        prop: "category",
        type: "select",
        label: "作业点类型",
        options: [
          {
            value: 1,
            label: "作业点",
          },
          {
            value: 2,
            label: "辅助点",
          },
        ],
        placeholder: "请选择作业点类型",
        colSpan: 24,
        maxlength: 24,
      },
    ],
    labelWidth: "120px", //标签的长度
  };
  // 表单校验
  #formRules: FormRules = {
    station_name: [{ required: true, message: "请输入作业点名称", trigger: "change" }],
    category: [{ required: true, message: "请选择作业点类型", trigger: "change" }],
  };
  get formData() {
    return this.#formData;
  }
  get formRules() {
    return this.#formRules;
  }
  get formOption() {
    return this.#formOption;
  }
  // 下拉框数据处理 有就打开处理
  // public getFormOption(optionsParams?: any) {
  //   const params = {
  //     page: 1,
  //     limit: 1000,
  //   };
  //   const p1 = getMaterialType(params).then((res: any) => {
  //     if (res) {
  //       const obj: any = res["materialTypes"];
  //       const { items } = obj;
  //       const materialTypeList = items.map((item: Item) => {
  //         return {
  //           label: item.name,
  //           value: item.id,
  //         };
  //       });
  //       const materialTypeId = this.#formOption.formItems.find((item) => item.field === "materialTypeId");
  //       materialTypeId && (materialTypeId.options = materialTypeList);
  //     }
  //   });
  //   const p2 = getMaterialUnit(params).then((res: any) => {
  //     if (res) {
  //       const obj: any = res["materialUnits"];
  //       const { items } = obj;
  //       const materialUnitList = items.map((item: Item) => {
  //         return {
  //           label: item.name,
  //           value: item.id,
  //         };
  //       });
  //       const materialUnitId = this.#formOption.formItems.find((item) => item.field === "materialUnitId");
  //       materialUnitId && (materialUnitId.options = materialUnitList);
  //     }
  //   });
  //   return Promise.all([p1, p2]);
  // }
}
